{include file="admin/common/header" /}
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label required">所属分类</label>
                    <div class="layui-input-inline">
                        <select name="article_cate_id" lay-verify="required" style="width:300px;">
                            <option value="">请选择分类</option>
                            {volist name="cates" id="vo"}
                            {php}
                            $selected = "";
                            if($vo['id'] == $data['article_cate_id']){
                            $selected = "selected";
                            }
                            {/php}
                            <option value="{$vo.id}" {$selected}>{$vo.title|raw}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-inline">
                        <input type="number" name="sort" autocomplete="off" placeholder="请输入排序"
                               class="layui-input" value="{$data.sort}">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">标题</label>
                <div class="layui-input-block ">
                    <input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="请输入标题"
                           class="layui-input" value="{$data.title}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">关键词|标签</label>
                <div class="layui-input-block">
                    <input type="text" id="keyword_name" name="keyword_names" autocomplete="off" placeholder="请选择关键字" class="layui-input" value="{$data.keyword_names}" readonly>
                    <input type="hidden" id="keyword_id" name="keyword_ids" autocomplete="off" value="{$data.keyword_ids}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-block">
                    <textarea name="desc" class="layui-textarea">{$data.desc}</textarea>
                </div>
            </div>

            <div class="layui-form-item huicmf-upload">
                <label class="layui-form-label">缩略图</label>
                <div class="layui-input-block">
                    <input type="text" name="thumb" value="{$data.thumb}"
                           onmouseover="hui_img_preview('thumb-select-input',this.value)"
                           onmouseout="layer.closeAll();" id="thumb-select-input" autocomplete="off"
                           class="layui-input">
                    <button type="button" class="layui-btn layui-btn-normal layUpload" id="picker_pic2"
                            data-multiple="false" data-input-id="thumb-select-input"
                            data-preview-id="thumb" data-type="image"><i class="layui-icon"></i>上传图片
                    </button>
                    <a class="layui-btn" style="margin-left: 10px;"
                       data-open-pic="/admin/index/file_list?type=one&select_id=thumb-select-input">
                        <i class="layui-icon">&#xe67c;</i>选择图片
                    </a>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">是否原创</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="original" value="1" title="是" {if($data.original eq 1)}checked{/if}>
                        <input type="radio" name="original" value="0" title="否" {if($data.original eq 0)}checked{/if}>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">来源|作者</label>
                    <div class="layui-input-inline">
                        <input type="text" name="origin" autocomplete="off" placeholder="请输入来源或作者"
                               class="layui-input" value="{$data.origin}">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">来源url</label>
                <div class="layui-input-block">
                    <input type="text" name="origin_url" lay-verify="url" autocomplete="off" placeholder="请输入来源url"
                           class="layui-input" value="{$data.origin_url}">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">阅读量</label>
                    <div class="layui-input-inline">
                        <input type="number" name="read" autocomplete="off" placeholder="请输入阅读量"
                               class="layui-input" value="{$data.read}">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">属性</label>
                    <div class="layui-input-inline">
                        <select name="type" style="width:300px;">
                            <option value="">请选择属性</option>
                            {foreach name="attributes" id="vo" key="k"}
                            <option value="{$k}" <?php if($data['type']== $k){echo "selected";} ?>>{$vo}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">内容</label>
                <div class="layui-input-block" id="container1EditorHtml" style="z-index: 0">
                    {php}echo \support\lib\Form::editor('content','container1',$val=$data['content'],
                    'width:100%;height:400px');{/php}
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block">
                    <input type="checkbox" name="auto_image" value="1" title="提取内容第一张图片为缩略图"
                           lay-skin="primary">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" title="启用" {if($data.status eq 1)}checked{/if}>
                    <input type="radio" name="status" value="0" title="禁用" {if($data.status eq 0)}checked{/if}>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <input type="hidden" id="id" name="id" value="{$data.id}">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="admin-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>

{include file="admin/common/footer" /}
<script>
  layui.use(['form', 'jquery', 'upload_hui','tagpicker'], function () {
    let form = layui.form;
    let $ = layui.jquery;
    let upload_hui = layui.upload_hui;
    let tagspicker = layui.tagpicker
    upload_hui.render();

    var tags = new tagspicker({
      'url': '/app/huiblog/module/keywords/get_keyword_cate',
      'target': 'keyword_name',
      'tag_ids': 'keyword_id',
      'tag_tags': 'keyword_name',
      'height': 500,
      'isDiy': 1
    });

    form.render();

    form.on('submit(admin-save)', function (data) {
      $.ajax({
        url: "/app/huiblog/blog/edit",
        data: JSON.stringify(data.field),
        dataType: 'json',
        contentType: 'application/json',
        type: 'post',
        success: function (res) {
          if (res.code === 200) {
            hui_msg(res.msg, 1, function () {
              window.location.reload();
            });
          } else {
            hui_msg(res.msg, 2);
          }
        }
      })
      return false;
    });
  })
</script>
<script>
</script>
</body>
</html>
